/// 业务类型选项
enum OrderTypeOption {
  all           ('', 0, '全部'),
  oil           ('refuel', 10, '油品'),
  lng           ('lng', 11, '天然气'),
  cng           ('cng', 11, '天然气'),
  h2            ('h2', 12, '氢气'),
  recharge      ('recharge', 20, '充值'),
  rechargeRefund('recharge_refund', 50, '退余额'),
  charge        ('charge', 70, '充电'),
  change        ('change', 70, '充电'),
  store         ('store', 30, '便利店'),
  oilStore      ('store', 40, '组合商品'), //主单
  integralMall  ('integral_mall', 90, '积分'),
  integralUnion ('integral_union', 91, '积分联盟'),
  tongFu        ('at_will', 92, '通付'),
  quanBao       ('value_added_services', 93, '付费券包'),
  washCar       ('car_wash', 94, '洗车服务');

  final String code;
  final int typeId;
  final String title;

  const OrderTypeOption(this.code, this.typeId, this.title);

  // 控制类型常量
  static const int controlOil = 0;
  static const int controlStore = 1;
  static const int controlRecharge = 2;
  static const int controlTongFu = 3;
  static const int controlCoupon = 4;

  // 获取控制的业务集合
  static List<int> get controlList => [
        controlOil,
        controlStore,
        controlRecharge,
        controlTongFu,
        controlCoupon,
      ];

  static List<int> getValues() {
    return [
      oil.typeId,
      // lng.typeId,
      // h2.typeId,
      recharge.typeId,
      // rechargeRefund.typeId,
      // charge.typeId,
      // change.typeId,
      store.typeId,
      // oilStore.typeId,
      // integralMall.typeId,
      // integralUnion.typeId,
      tongFu.typeId,
      // quanBao.typeId,
      // washCar.typeId,
    ];
  }

  // 获取业务类型描述
  static String getDesc(int? typeId) {
    for (final value in OrderTypeOption.values) {
      if (value.typeId == typeId) {
        return value.title;
      }
    }
    return 'orderType=$typeId';
  }

  /// 判断业务
  static bool canPrintOrSpeak(List<int> mSelectIntList, int controlType, int typeId) {
    if (mSelectIntList.isEmpty) {
      return true;
    }

    // 使用 if-else 替代 switch，实现与枚举的强关联
    if (controlType == controlCoupon) {
      return mSelectIntList.contains(controlType);
    } else if (controlType == all.typeId ||
        controlType == oil.typeId ||
        controlType == lng.typeId ||
        controlType == h2.typeId) {
      return mSelectIntList.contains(controlOil);
    } else if (controlType == recharge.typeId) {
      return mSelectIntList.contains(controlRecharge);
    } else if (controlType == rechargeRefund.typeId) {
      return true;
    } else if (controlType == charge.typeId) {
      return true;
    } else if (controlType == oilStore.typeId ||
        controlType == store.typeId) {
      return mSelectIntList.contains(controlStore);
    } else if (controlType == integralMall.typeId) {
      return true;
    } else if (controlType == integralUnion.typeId) {
      return true;
    } else if (controlType == tongFu.typeId) {
      return mSelectIntList.contains(controlTongFu);
    } else {
      return true;
    }
  }

  static String format(int orderStatus) {
    for (final value in OrderTypeOption.values) {
      if (value.typeId == orderStatus) {
        return value.title;
      }
    }
    return 'orderType=$orderStatus';
  }
}
